#include "FileSystem.h"

#include <windows.h>

namespace platform {

bool FileSystem::SizeLimit::isOverLimit(void) {
	unsigned __int64 szFree;
	unsigned __int64  szTotal;

	BOOL bOK = ::GetDiskFreeSpaceEx(m_location.getTStr(),
									(PULARGE_INTEGER) &szFree,
									(PULARGE_INTEGER) &szTotal,
									NULL);
	if (!bOK) return false;

	switch (m_type) {
		case SLT_FREE_PERCENT:
			// first time this function is executed,
			// we should calculate the total expected
			// "free" size, based on the percentage
			szTotal = szTotal >> 20;  // bytes to MB
			m_value = ((unsigned long) (szTotal / 100)) * m_value;
			// now continue to next case
		case SLT_FREE_SIZE_MB:
			szFree = szFree >> 20;  // bytes to MB
			return (szFree <= m_value);
	}

	return true;
}

}  //  end namespace